package hufu.service.util;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class QlcSpider {

	public static Map<String, String> getEditionAndNum()
	{
		Map<String, String> map = new HashMap<String, String>();
		String temp = SpiderUtils.doPost(
				"http://www.zhcw.com/kaijiang/zhcw_qlc_index.html", map,
				"UTF-8");
		String winNum = winNum(temp);
		String edition = edition(temp);
		map.put("winNum", winNum);
		map.put("edition", edition);
		return map;
	}
	
	public static String edition(String temp) {
		String s[] = temp.split("selected>");
		String str = (String) s[1].subSequence(0, 7);
		return str;
	}

	public static String winNum(String temp) {
		String s[] = temp.split("<li class=\"sum\">中奖号码：</li>");
		String str = s[1].split("<dt>本期销售额： &nbsp;<span>")[0].split("</ul>")[0];
		String dest = format(str);
		dest = keepNum(dest);
		return dest;
	}

	public static String format(String str) {
		Pattern p = Pattern.compile("\\s*|\t|\r|\n");
		Matcher m = p.matcher(str);
		String dest = m.replaceAll("");
		return dest;
	}

	public static String keepNum(String str) {
		Pattern p = Pattern.compile("[^0-9]");
		Matcher m = p.matcher(str);
		String dest = m.replaceAll("");
		return dest;
	}
	
	public static void main(String[] args) {
//		Map map = new HashMap();
//		String temp = SpiderUtils.doPost(
//				"http://www.zhcw.com/kaijiang/zhcw_qlc_index.html", map,
//				"UTF-8");
//		System.out.println("返回的消息是:" + temp);
//		String winNum = winNum(temp);
//		System.out.println("号：" + winNum);
//		String edition = edition(temp);
//		System.out.println("期：" + edition);
	}
}
